- /* slflrand.cpp by K.Tsuru */
- // function ID = 2003
- /***************************************************************************
- SLong and SInteger classes
- It provides a random number with the radix (= DRADIX or BRADIX).
- radix = DRADIX in default.
- When size = 0 it is taken as minArraySize.
- If 'size' has a value which is greater than the maximum size it is adjusted
- to the maximum one.
- ***************************************************************************/
- #ifndef SN_H
- #include "sn.h"
- #endif
-
- #include <time.h>
- SLong LRand(uint size, fType radix){
- SNumber::NumberType tp = (radix > DRADIX) ? SNumber::BIN_INT : SNumber::DEC_INT;
- fType rdx = (radix > DRADIX) ? BRADIX : DRADIX;
- uint max_sz = SNManager::SNMaxSize(tp);
- if(!size) size = minArraySize;
- else if(size > max_sz) size = max_sz;
-
- SLong result(tp, size);
- FigBlock a(size);
- fType* p = a.Elements();
- time_t t;
- static uint seed = (uint)time(&t);
-
- srand(seed);
- for(uint j = 0; j < size ; j++) p[j] = fType( rand() % (int)rdx );
- a.clear(size);
- seed = (uint)rand(); // set new seed for next call.
- result.SetFigBlock(a, 1); // result.CheckArray(); done
-
- return result;
- }
slflrand.cpp : last modifiled at 2017/03/17 11:10:48(1,186 bytes)
created at 2017/10/07 10:26:49
The creation time of this html file is 2017/11/09 14:52:03 (Thu Nov 09 14:52:03 2017).